package com.ebelter.btcomlib.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ebelter.btcomlib.R;
import com.ebelter.btcomlib.utils.ViewUtils;


/**
 * 组合控件7 不知道怎么起名字了 还是按序号来吧
 */

public class CombinView7 extends LinearLayout{
    public CombinView7(Context context) {
        this(context,null);
    }


    public CombinView7(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }




    public CombinView7(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CombinView7);
        if (typedArray != null) {
            title1 = typedArray.getString(R.styleable.CombinView7_title1);
            title2 = typedArray.getString(R.styleable.CombinView7_title2);
            title3 = typedArray.getString(R.styleable.CombinView7_title3);
            title31 = typedArray.getString(R.styleable.CombinView7_title31);
            title4 = typedArray.getString(R.styleable.CombinView7_title4);
            typedArray.recycle();
        }

        initView(getContext());
        initDatas();


    }

    private void initDatas() {
        textView1.setText(title1);
        textView2.setText(title2);
        textView3.setText(title3);
        cb7_title31.setText(title31);
        textView4.setText(title4);
    }

    private String title1;
    private String title2;
    private String title3;
    private String title31;
    private String title4;

    private TextView textView1;
    private TextView textView2;
    private TextView textView3;
    private TextView cb7_title31;
    private TextView textView4;

    private View cb7_title31_hl;

    private LinearLayout root;






    private void initView(Context context) {
        View view =  View.inflate(context, R.layout.cb7_layout, this);//把那个布局当做是自己的孩子
        root = view.findViewById(R.id.cb7_root_ll);
        textView1=view.findViewById(R.id.cb7_title1);
        textView2=view.findViewById(R.id.cb7_title2);
        textView3=view.findViewById(R.id.cb7_title3);
        cb7_title31=view.findViewById(R.id.cb7_title31);
        cb7_title31_hl=view.findViewById(R.id.cb7_title31_hl);
        textView4=view.findViewById(R.id.cb7_title4);
    }


    public void setDisplay31(boolean display31){
        if (display31){
            ViewUtils.displayView(cb7_title31);
            ViewUtils.displayView(cb7_title31_hl);
        }else {
            ViewUtils.goneView(cb7_title31);
            ViewUtils.goneView(cb7_title31_hl);
        }
    }
//
//    @Override
//    protected void onDraw(Canvas canvas) {
//        super.onDraw(canvas);
//    }

    public void setTitleSize(int index, int sp) {
        if (index==1){
            ViewUtils.setTextSize(textView1,sp);
        }else if (index==2){
            ViewUtils.setTextSize(textView2,sp);
        }else if (index==3){
            ViewUtils.setTextSize(textView3,sp);
        }else if (index==4){
            ViewUtils.setTextSize(textView4,sp);
        }
    }

    public void setTitleSizes(int sp) {
        ViewUtils.setTextSize(textView1,sp);
        ViewUtils.setTextSize(textView2,sp);
        ViewUtils.setTextSize(textView3,sp);
        ViewUtils.setTextSize(cb7_title31,sp);
        ViewUtils.setTextSize(textView4,sp);
    }
}
